import 'package:flutter/material.dart';
import 'package:lunar/lunar.dart';
import 'package:todo_app/constants/DColor.dart';
import 'package:todo_app/constants/Screen.dart';
import 'package:todo_app/layout/Gaps.dart';
import 'package:todo_app/utils/ExtHelper.dart';

class CalendarDayWidget extends StatelessWidget {
  const CalendarDayWidget({
    super.key, 
    required this.selected, 
    required this.date, 
    required this.current, 
    required this.isLastMonthDay, 
    required this.isNextMonthDay, 
    required this.onTap,
    this.hasValue = false
  });

  final bool selected;
  final DateTime date;
  final DateTime current;
  final bool isLastMonthDay;
  final bool isNextMonthDay;
  final ValueChanged<DateTime> onTap;
  final bool hasValue;

  @override
  Widget build(BuildContext context) {
    final size = Screen.width / 7 - 10.dp;
    final isCurrent = current.isSameDay(date);
    return GestureDetector(
      onTap: () => onTap(date),
      child: SizedBox(
        width: size,
        height: size,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular((size - 5.dp) / 2),
                color: selected ? Colors.white : isCurrent ? Colors.white.withOpacity(0.3) : Colors.transparent,
              ),
              height: size - 5.dp,
              width: size - 5.dp,
              child: Center(
                child: Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(
                        text: '${date.day}\n',
                        style: TextStyle(
                          fontSize: 14.dp,
                          color: selected ? DColor.primary : Colors.white,
                          fontWeight: FontWeight.bold,
                          height: 1
                        ),
                      ),
                      TextSpan(
                        text: isCurrent ? '今日' : Lunar.fromDate(date).getDayInChinese(),
                        style: TextStyle(
                          fontSize: 10.dp,
                          color: selected ? DColor.primary : Colors.white,
                          letterSpacing: -0.4.dp,
                          height: 1.1
                        ),
                      )
                    ]
                  ),
                  textAlign: TextAlign.center,
                ),
              )
            ),
            Offstage(
              offstage: isLastMonthDay || isNextMonthDay,
              child: Container(
                margin: EdgeInsets.only(top: 2.dp),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5.dp),
                  color: hasValue ?  Colors.white : Colors.transparent,
                ),
                width: 5.dp,
                height: 5.dp,
              ),
            )
          ],
        ),
      ),
    );
  }
}